<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>文件列表</title>
    <% include("../common/css.html"){} %>
</head>

<body>
<% include("../layout/loading.html"){} %>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">日期：</label>
                        <div class="layui-input-inline mr0">
                            <input id="edtDate" class="layui-input date-icon" type="text" autocomplete="off"
                                   placeholder="请选择日期范围"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="filesTable" lay-filter="filesTable"></table>
        </div>
    </div>

</div>

<!-- js部分 -->
<% include("../common/js.html"){} %>
<script>
    layui.use(['layer', 'form', 'table', 'util', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#filesTable',
            url: '/sys/files/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'},
                {field: 'batchNum', title: '上传批次号', minWidth: 320},
                {field: 'fileName', title: '文件名'},
                {
                    field: 'fileSize', title: '文件大小', templet: function (d) {
                        return d.fileSize + "kb"
                    }
                },
                {field: 'fileType', title: '文件类型'},
                {field: 'timeUsed', title: '耗时/ms'},
                {
                    templet: function (d) {
                        return d.createTime;
                    }, title: '上传时间'
                },
                {
                    title: '操作', align: 'center', width: 100, fixed: 'right',
                    toolbar: '<p><a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="show">预览/下载</a></p>'
                }
            ]]
        });

        // 时间范围
        laydate.render({
            elem: '#edtDate',
            type: 'date',
            range: true,
            theme: 'molv'
        });

        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var searchDate = $('#edtDate').val().split(' - ');
            insTb.reload({
                where: {
                    startDate: searchDate[0],
                    endDate: searchDate[1]
                }
            });
        });

        /* 表格工具条点击事件 */
        table.on('tool(filesTable)', function (obj) {
            if ('show' === obj.event) { // 详情
                if (obj.data.fileType.indexOf("image") == 0) {
                    showImg(obj.data.fileUrl)
                } else {
                    window.open(obj.data.fileUrl)
                }
            }
        });

    });
</script>

</body>
</html>